#include "user.hpp"
#include "protocol_dist.hpp"

User::User()
{
    sessionTime = winux::GetUtcTime();
}
void User::login(winux::SharedPointer<ws::WsHttpRequestCtx> ctx)
{
    _ctx = ctx;
    this->isLogged = true;
    this->sessionTime = (int)GetUtcTime();
}
void User::logout()
{
    this->isLogged = false;
    _ctx.detach();
}
void User::send(Protocol *msg)
{
    if (_ctx)
    {
        _ctx->send(ws::OpCode::dataText, false, msg->toMixed().json());
    }
}
winux::SimplePointer<ProtocolObjectUser> User::toProtocol()
{
    winux::SimplePointer<ProtocolObjectUser> p;
    p.attachNew(new ProtocolObjectUser());
    p->sessionTime = this->sessionTime;
    p->token = this->token;
    return p;
}